package com.wn.manpower.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.PageBean;
import com.wn.entity.ChangePosts;
import com.wn.entity.Hr;
import com.wn.manpower.mapper.ChangePostsMapper;
import com.wn.manpower.mapper.HumanResourcesMapper;
import com.wn.manpower.service.ChangePostsService;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dzj
 * date: 2022/10/20
 */
@Service
public class ChangePostsServiceImp implements ChangePostsService {

    @Autowired
    private ChangePostsMapper changePostsMapper;

    @Autowired
    private HumanResourcesMapper humanResourcesMapper;

    @Override
    public void add(ChangePosts changePosts) {
        Hr hr=new Hr();
        hr.setName(changePosts.getEmployee().getName());
        List<Hr> hrs = humanResourcesMapper.getByCondition(hr);
        hr.setId(hrs.get(0).getId());
        changePosts.setEmployee(hr);
        changePostsMapper.add(changePosts);
    }

    @Override
    public void update(ChangePosts changePosts) {
        Hr hr=new Hr();
        hr.setName(changePosts.getEmployee().getName());
        List<Hr> hrs = humanResourcesMapper.getByCondition(hr);
        hr.setId(hrs.get(0).getId());
        changePosts.setEmployee(hr);
        changePostsMapper.update(changePosts);
    }

    @Override
    public void del(int id) {
        changePostsMapper.del(id);
    }

    @Override
    public ChangePosts getById(int id) {
        return changePostsMapper.getById(id);
    }

    @Override
    public ChangePosts getByActivitiInstanceId(String ActivitiInstanceId) {
        return changePostsMapper.getByActivitiInstanceId(ActivitiInstanceId);
    }

    @Override
    public PageBean<ChangePosts> getPageByCondition(ChangePosts changePosts, int currPage, int pageSize) {
        Page<Object> page = PageHelper.startPage(currPage, pageSize);
        List<ChangePosts> changePostsList = changePostsMapper.getByCondition(changePosts);
        PageBean<ChangePosts> pageBean = PageBeanUtil.getPageBean(changePostsList, page, currPage, pageSize);
        return pageBean;
    }
}
